package typejump.objects;
import java.util.Hashtable;

public class ObjectManager {
	private static Hashtable<String, GameObject> objects = new Hashtable<String, GameObject>();
	private static Hashtable<GameObject, String> keys = new Hashtable<GameObject, String>();
	private static int curID = 0;
	
	public static String add(GameObject obj) {
		String key = null;
		do {
			key = String.valueOf(curID++);
		} while (objects.containsKey(key));
		
		add(key, obj);
		return key;
	}
	
	public static void add(String id, GameObject obj) {
		objects.put(id, obj);
		keys.put(obj, id);
	}
	
	public static String getId(GameObject obj) {
		return keys.get(obj);
	}
	
	public static GameObject get(String id) {
		return objects.get(id);
	}
	
	public static void remove(String id) {
		keys.remove(objects.get(id));
		objects.remove(id);
	}
	
	public static void remove(GameObject obj) {
		objects.remove(keys.get(obj));
		keys.remove(obj);
	}
}
